package com.jia.utils;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;

import com.jia.R;

/**
 * [Xml工具类] <br>
 *
 * @author [jia.xiuya] <br>
 * @version 1.0 <br>
 * @taskId <br>
 * @CreateDate 13-7-31 <br>
 * @see com.jia.utils <br>
 * @since V7.3<br>
 */
public final class XmlUtil {

    public static String getEventsFromAnXMLFile(Activity activity)
            throws XmlPullParserException, IOException {
        StringBuffer sb = new StringBuffer();
        Resources res = activity.getResources();
        XmlResourceParser xpp = res.getXml(R.xml.test_xml);

        xpp.next();
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_DOCUMENT) {
                sb.append("******Start document");
            }
            else if (eventType == XmlPullParser.START_TAG) {
                sb.append("\nStart tag " + xpp.getName());
            }
            else if (eventType == XmlPullParser.END_TAG) {
                sb.append("\nEnd tag " + xpp.getName());
            }
            else if (eventType == XmlPullParser.TEXT) {
                sb.append("\nText " + xpp.getText());
            }
            eventType = xpp.next();
        }//eof-while
        sb.append("\n******End document");
        return sb.toString();
    }//eof-function
}
